<template>
  <div class="mobile-cont">
    <video
      autoplay
      loop
      muted
      playsinline
      :src="store.index.background_mp4"
      :poster="store.index.background_cover"
      id="car_audio"
    ></video>
    <!-- <video
      autoplay
      loop
      muted
      playsinline
      src="@assets/temp-video2.mp4"
      poster="@assets/image/poster.jpg"
    ></video> -->
    <img src="@assets/image/2024.png" class="img-2024" />

    <div class="home-box">
      <img v-if="store.status === 0" class="home-box-title-text" src="@assets/image/home-box-text.png" />
      <img v-if="store.status === 1" class="home-box-title-text" src="@assets/image/home-box-text2.png" />
      <img v-if="store.status === 2" class="home-box-title-text" src="@assets/image/home-box-text3.png" />
      <img class="home-box-light" src="@assets/image/light.png" />
      <div class="countdown-sec" v-if="store.status === 0">
        <Countdown endTime="2024-02-09 18:00:00" />
      </div>
      <!-- 进行中/已结束 -->
      <div>
        <div class="ing-text" v-if="store.status === 1">选择直播平台</div>
        <div class="ing-text" v-if="store.status === 0">扫码了解详情</div>
        <div class="platfrom-group">
          <img
            v-for="(item, index) in store.index.platform"
            :src="item.icon"
            @click="scanQrcode([item.icon],item.icon); qrcode = item.qrcode"
            :key="index"
            width="40px"
            height="40px"
          />
        </div>
        <div class="finish-text" v-show="store.status == 2">预约活动已结束</div>
      </div>
      <div style="position: relative; padding-bottom: 21px">
        <img class="home-box-title-sec" src="@assets/image/home-box-title.png" />
        <img class="QR-code" :src="qrcode" @click="scanQrcode([qrcode],qrcode);" />
      </div>
    </div>

    <div class="users-number">
      <img src="@assets/image/right.png" />
      <div>
        已有<span class="number">{{ store.index.join_virtually }}</span
        >AI梦想创作者申请入场券
      </div>
      <img src="@assets/image/right.png" />
    </div>
    <my-swiper :list="store.index.persion" style="height: 200px" />

    <div class="btn">
      <img @click="show = true" src="@assets/image/finish.png" v-if="!store.lock" />
      <img src="@assets/image/finish-d.png" v-if="store.lock" />
    </div>
    <div style="height: 20px"></div>
  </div>
  <Dialog v-if="show" @close="close" />
</template>

<script setup>
import Countdown from "../components/Countdown.vue";
import Dialog from "../components/Dialog.vue";
import mySwiper from "../components/Swiper.vue";
import { ref, onMounted } from "vue";
import { getwxConfig, previewImage } from "@/utils/index";
import { useMobileStore } from "@/api/store";

const store = useMobileStore();
const qrcode = ref(null);
const init = async () => {
  await store.init;
  qrcode.value = store.index.reservation_qrcode;
};

const show = ref(false);
const close = (val) => {
  show.value = val;
};

const wxInit = () => {
  // const url = 'https://chunwan.waytoagi.com';
  const url = window.location.href.split("#")[0];
  return store.share(url).then((res) => {
    getwxConfig(url, res);
  });
};

const scanQrcode = (url, index) => {
  previewImage(url, index)
}

onMounted(() => {
  init();
  wxInit();
  //一般情况下，这样就可以自动播放了，但是一些奇葩iPhone机不可以
  document.getElementById("car_audio").play();
  //必须在微信Weixin JSAPI的WeixinJSBridgeReady才能生效
  document.addEventListener(
    "WeixinJSBridgeReady",
    function () {
      document.getElementById("car_audio").load();
      document.getElementById("car_audio").pause();
      document.getElementById("car_audio").play();
      document.getElementById("video").play();
    },
    false
  );
  document.addEventListener(
    "touchstart",
    function () {
      var video = document.getElementById("car_audio");
      video.play();
    },
    false
  );
});
</script>

<style lang="less" scoped>
.mobile-cont {
  // font-weight: 400;  
  background-image: url("@assets/image/home-bg.png");
  background-size: 100% auto;
  background-attachment: scroll;
  background-repeat: no-repeat;
  background-position: top left;
  position: relative;
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  // font-family: MyCustomFont;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  text-align: center;

  video {
    position: relative;
    height: 507px;
    top: -1px;
    width: 100%;
    left: 0;
    right: 0;
  }
  .img-2024 {
    width: 45%;
    padding-top: 40px;
    position: absolute;
  }

  .home-box {
    width: 100%;
    // padding: 0 10px;
    margin-top: 400px;
    height: 463px;
    background-image: url("@assets/image/box.png");
    // background-size: 95% auto;
    background-size: contain;
    background-repeat: no-repeat;
    // background-position: top center;
    position: absolute;

    .home-box-light {
      width: 40px;
      position: absolute;
      top: 20px;
      left: 0px;
    }

    .countdown-sec {
      width: 73%;
      margin: 0 auto;
      margin-top: 10px;
    }
    .ing-text {
      color: #fff8c5;
      font-size: 16px;
      margin-bottom: 10px;
      margin-top: 10px;
    }
    .platfrom-group {
      display: flex;
      gap: 10px;
      justify-content: center;
    }
    .finish-text {
      background-color: #c8c8c8;
      color: #888;
      text-align: center;
      padding: 10px 0;
      width: 54%;
      margin: 10px auto -44px auto;
      z-index: 1;
      position: relative;
      &::before {
        content: "";
        width: 0;
        height: 0;
        left: -20px;
        top: 0;
        position: absolute;
        border-right: 10px solid #c8c8c8;
        border-left: 10px solid transparent;
        border-bottom: 20px solid transparent;
        border-top: 20px solid transparent;
      }
      &::after {
        content: "";
        width: 0;
        height: 0;
        right: -20px;
        top: 0;
        position: absolute;
        border-right: 10px solid transparent;
        border-left: 10px solid #c8c8c8;
        border-bottom: 20px solid transparent;
        border-top: 20px solid transparent;
      }
    }
    .home-box-title-sec {
      margin-top: 5px;
      width: 75%;
    }
    .home-box-title-text {
      margin-top: 45px;
      width: 60%;
    }
    .QR-code {
      width: 33%;
      position: absolute;
      bottom: 0px;
      left: 50%;
      margin-bottom: 13px;
      transform: translateX(-50%);
      padding: 5px;
      background-color: #5c0902;
    }
  }
  .users-number {
    position: absolute;
    top: 112vh;
    margin-top: 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 24px;
    color: #ffb778;
    img {
      display: inline-block;
      width: 60px;
      height: 20px;
      &:first-child {
        transform: rotate(180deg);
      }
    }
    .number {
      color: #f7dfb4;
      font-size: 28px;
      font-weight: bold;
      margin-left: 5px;
      margin-right: 5px;
    }
  }
  .btn {
    height: 38px;
    width: 148px;
    margin-top: 30px;
    margin-bottom: 30px;
    padding-bottom: 60px;
    position: absolute;
    top: 150vh;
    img {
      width: inherit;
      cursor: pointer;
    }
  }
}
</style>
